<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 10/24/18
 * Time: 10:51 AM
 */

namespace console\members\wodrow\reverse_proxy;


use yii\base\Component;

class Client extends Component
{
    public function connect()
    {
        $_c = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
        $_c->on("connect", function(\swoole_client $client) {
            var_dump("connect");
            $client->send(date("Y-m-d H:i:s")."\n");
        });
        $_c->on('receive', function (\swoole_client $client, $data){
            echo "Receive: $data";
            sleep(2);
            $client->send(date("Y-m-d H:i:s")."\n");
            sleep(5);
        });
        $_c->on("error", function(\swoole_client $client){
            exit("error\n");
        });
        $_c->on("close", function(\swoole_client $client){
            echo "Connection close\n";
        });
        $_c->connect('0.0.0.0', 9501);
    }
}